<template>
	<div class="info">
		<div class="shang">
			<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
				  <el-form-item label="设备GRN" prop="grn">
					<el-input v-model="ruleForm.grn" style="width:50%"></el-input>
				  </el-form-item>
				   <el-form-item label="topic" prop="topic">
					<el-input v-model="ruleForm.topic"></el-input>
				  </el-form-item>
				  <el-form-item label="消息" prop="message">
					<el-input v-model="ruleForm.message" type="textarea"></el-input>
				  </el-form-item>
				  <el-form-item style="text-align:center">
			  <el-button @click="resetForm('ruleForm')">重置</el-button>
					 <el-button type="primary" @click="submitForm('ruleForm')">发送</el-button>
				  </el-form-item>
			</el-form>
		</div>
	</div>
</template>
<script>
export default {
	name:'test',
	data() {
		return {
			ruleForm: {
				grn: '',
				topic: '',
				message:''
			},
			rules: {
				grn: [
					{ required: true, message: '请输入设备GRN', trigger: 'blur' },
					{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
				],
				topic: [
					{ required: true, message: '请输入话题', trigger: 'blur' }
				],
				message: [
					{ required: true, message: '请输入相关信息', trigger: 'blur' },
					{ min:10,max:100,message:'信息输入长度不正确',trigger:'blur'}
				]
			}
		};
	},
	methods: {
		submitForm(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
					alert('submit!');
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		resetForm(formName) {
			this.$refs[formName].resetFields();
		}
	}
}
</script>
<style scoped>
	.info{ width:90%;margin:20px;}
	.shang{ width:90%;margin-top:5px;}
</style>